﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Data.Entity.ModelConfiguration.Conventions.Edm.Db;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Conventions.Configuration;
using System.Data.Entity;
using System.Data.Entity.Database;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;
using System.Configuration;
using MSBTC.WinFormHelpers;

namespace MSBTC.Model
{
    
    public class PMSContext : DbContext
    {
        
        public PMSContext()
            :base("PMS") //ConfigurationManager.ConnectionStrings["PMS_Context"].ConnectionString)

        {
            DbDatabase.SetInitializer<DbContext>(null);
        }

        //content
        public DbSet<Customer> Customers { get; set; }
        public DbSet<Supplier> Suppliers { get; set; }
        public DbSet<Equipment> Equipments { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<Session> Sessions { get; set; }
        public DbSet<Labor> Labors { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<DeliveryReceipt> DeliveryReceipts { get; set; }
        public DbSet<Project> Projects { get; set; }
        public DbSet<Material> Materials { get; set; }
        public DbSet<Lost> Losts { get; set; }
        public DbSet<PrchOrder> PurchOrder { get; set; }
        public DbSet<ProjEquip> PrjEqs { get; set; }
        public DbSet<MaterialsInventory> MaterialsInventorys { get; set; }
        public DbSet<Requisition> Requests { get; set; }
        public DbSet<ProjMat> PrjMatls { get; set; }
        public DbSet<Mat_Maintenance> Mat_Maintenances { get; set; }
        public DbSet<Unit> Units { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            
            base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Customer>().ToTable("dbo.Customer_TB");
            modelBuilder.Entity<Customer>().Property(c => c.Customerid_PK);

            modelBuilder.Entity<Supplier>().ToTable("dbo.Supplier_TB");
            modelBuilder.Entity<Supplier>().Property(s => s.Supplierid_PK);

            modelBuilder.Entity<Equipment>().ToTable("dbo.Equipment_TB");
            modelBuilder.Entity<Equipment>().Property(e => e.Equipmentid_PK);

            modelBuilder.Entity<User>().ToTable("dbo.User_TB");
            modelBuilder.Entity<User>().Property(u => u.Userid_PK);

            modelBuilder.Entity<Session>().ToTable("dbo.Session_TB");
            modelBuilder.Entity<Session>().Property(s => s.Sessionid_PK);

            modelBuilder.Entity<Labor>().ToTable("dbo.Labour_TB");
            modelBuilder.Entity<Labor>().Property(l => l.Labourid_PK);

            modelBuilder.Entity<Category>().ToTable("dbo.Category_TB");
            modelBuilder.Entity<Category>().Property(c => c.Categoryid_PK);

            modelBuilder.Entity<DeliveryReceipt>().ToTable("dbo.DeliveryReciept_TB");
            modelBuilder.Entity<DeliveryReceipt>().Property(dr => dr.DRid_PK);

            modelBuilder.Entity<Project>().ToTable("dbo.Project_TB");
            modelBuilder.Entity<Project>().Property(p => p.Projectid_PK);

            modelBuilder.Entity<Material>().ToTable("dbo.Materials_TB");
            modelBuilder.Entity<Material>().Property(m => m.Materialsid_PK);

            modelBuilder.Entity<Lost>().ToTable("dbo.Lost_TB");
            modelBuilder.Entity<Lost>().Property(l => l.Lostid_PK);

            modelBuilder.Entity<PrchOrder>().ToTable("dbo.PurchaseOrder_TB");
            modelBuilder.Entity<PrchOrder>().Property(p => p.poid_PK);

            modelBuilder.Entity<ProjEquip>().ToTable("dbo.ProjEquip_TB");
            modelBuilder.Entity<ProjEquip>().Property(pe => pe.Relid_PK);

            modelBuilder.Entity<MaterialsInventory>().ToTable("dbo.MaterialsInventory_TB");
            modelBuilder.Entity<MaterialsInventory>().Property(m => m.MaterialsInventoryid_PK);

            modelBuilder.Entity<Requisition>().ToTable("dbo.Requisition_TB");
            modelBuilder.Entity<Requisition>().Property(r => r.ID_PK);

            modelBuilder.Entity<ProjMat>().ToTable("dbo.ProjMat_TB");
            modelBuilder.Entity<ProjMat>().Property(p => p.PjMatid_PK);

            modelBuilder.Entity<Mat_Maintenance>().ToTable("dbo.MatData_TB");
            modelBuilder.Entity<Mat_Maintenance>().Property(m => m.DataID);


            modelBuilder.Entity<Unit>().ToTable("dbo.Unit_TB");
            modelBuilder.Entity<Unit>().Property(m => m.UnitID);

        }
    }
}
